import request from '@/utils/request'
import { Axios, AxiosResponse } from 'axios'

export interface SaveRoles{
  id?:number
  name:string
  code:string
  description:string
}

export const getAllRole = ():Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: '/boss/role/all'
  })
}

export const saveOrUpdate = (data:SaveRoles):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/role/saveOrUpdate',
    data
  })
}

export const deleteRole = (id:number):Promise<AxiosResponse> => {
  return request({
    method: 'DELETE',
    url: `/boss/role/${id}`
  })
}

export const finduser = (id:number):Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: `/boss/role/${id}`
  })
}

export const getRolePages = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/role/getRolePages',
    data
  })
}

export const allocateUserRoles = (data:any):Promise<AxiosResponse> => {
  return request({
    method: 'POST',
    url: '/boss/role/allocateUserRoles',
    data
  })
}

export const findUserAllRoles = (userId:number):Promise<AxiosResponse> => {
  return request({
    method: 'GET',
    url: `/boss/role/user/${userId}`
  })
}
